import React from 'react';
import { Navigate } from 'react-router-dom';
import AppLayout from '../layouts/AppLayout.jsx';
import Login from '../views/Login.jsx';
import Main from '../views/Main.jsx';
import MachineGroup from '../views/machine/MachineGroup.jsx';
import MachineList from '../views/machine/MachineList.jsx';
import UserMachineAlarm from '../views/machine/UserMachineAlarm.jsx';
import MachineMaps from '../views/machine/MachineMaps.jsx';
import ProductType from '../views/product/ProductType.jsx';
import Product from '../views/product/Product.jsx';
import ProductTag from '../views/product/ProductTag.jsx';
import ProductLibrary from '../views/product/ProductLibrary.jsx';
import Coupons from '../views/product/Coupons.jsx';
import AdvertsGallery from '../views/adverts/AdvertsGallery.jsx';
import AdvertGroup from '../views/adverts/AdvertGroup.jsx';
import MachineAdvertGroup from '../views/adverts/MachineAdvertGroup.jsx';
import MachineAdvertLabel from '../views/adverts/MachineAdvertLabel.jsx';
import RequireAuth from './RequireAuth.jsx';
import Password from '../views/Password.jsx';
import WalletAccount from '../views/wallet/Account.jsx';
import WalletDetail from '../views/wallet/Detail.jsx';
import WalletRecord from '../views/wallet/Record.jsx';
import WalletSubscribe from '../views/wallet/Subscribe.jsx';
import WalletTopup from '../views/wallet/Topup.jsx';
import OrderList from '../views/order/Order.jsx';
import OrderRefund from '../views/order/OrderRefund.jsx';
import RechargeRecord from '../views/order/RechargeRecord.jsx';
import RenewalRecord from '../views/order/RenewalRecord.jsx';
import WithdrawalRecord from '../views/order/WithdrawalRecord.jsx';
import DateProfit from '../views/statistics/DateProfit.jsx';
import AdverStatistics from '../views/statistics/AdverStatistics.jsx';
import MachineProfit from '../views/statistics/MachineProfit.jsx';
import ProductProfit from '../views/statistics/ProductProfit.jsx';
import UserProfit from '../views/statistics/UserProfit.jsx';
import WarnStatistics from '../views/statistics/WarnStatistics.jsx';
import User from '../views/system/User.jsx';
import Certificate from '../views/system/Certificate.jsx';
import Email from '../views/system/Email.jsx';
import AppVersion from '../views/system/AppVersion.jsx';
import ICard from '../views/system/ICard.jsx';
import IDardList from '../views/system/IDardList.jsx';
import DictionaryData from '../views/system/DictionaryData.jsx';
// 新增：补充缺失的权限页面导入，避免 ReferenceError
import Role from '../views/authority/Role.jsx';
import PrivacyAgreementInfo from '../views/authority/PrivacyAgreementInfo.jsx';
import Operation from '../views/authority/Operation.jsx';
import MenuPage from '../views/authority/Menu.jsx';
// 新增：登录日志与授权管理页面导入
import LoginInfo from '../views/authority/LoginInfo.jsx';
import Authorization from '../views/authority/Authorization.jsx';
// 新增：帮助中心-客服聊天
import HelpCenterChat from '../views/helpcenter/Chat.jsx';
// 新增：推广配置页
import PromoteConfig from '../views/promote/Config.jsx';

// 模仿 admin-web：把根路径作为布局容器，并将首页设为 /main
const routes = [
  { path: '/login', element: <Login /> },
  {
    path: '/',
    element: <RequireAuth />,
    children: [
      {
        path: '/',
        element: <AppLayout />,
        children: [
          { index: true, element: <Navigate to="main" replace /> },
          { path: 'main', element: <Main /> },
          { path: 'machine/group', element: <MachineGroup /> },
          { path: 'machine/list', element: <MachineList /> },
          { path: 'machine/alarm', element: <UserMachineAlarm /> },
          { path: 'machine/maps', element: <MachineMaps /> },
          { path: 'product/type', element: <ProductType /> },
          { path: 'product/list', element: <Product /> },
          { path: 'product/tag', element: <ProductTag /> },
          { path: 'product/library', element: <ProductLibrary /> },
          { path: 'product/coupons', element: <Coupons /> },
          { path: 'adverts/gallery', element: <AdvertsGallery /> },
          { path: 'adverts/group', element: <AdvertGroup /> },
          { path: 'adverts/machine-group', element: <MachineAdvertGroup /> },
          { path: 'adverts/machine-label', element: <MachineAdvertLabel /> },
          { path: 'password', element: <Password /> },
          { path: 'statistics/dateprofit', element: <DateProfit /> },
          { path: 'statistics/adver', element: <AdverStatistics /> },
          { path: 'statistics/machineprofit', element: <MachineProfit /> },
          { path: 'statistics/productprofit', element: <ProductProfit /> },
          { path: 'statistics/userprofit', element: <UserProfit /> },
          { path: 'statistics/warn', element: <WarnStatistics /> },
          { path: 'order/list', element: <OrderList /> },
          { path: 'order/refund', element: <OrderRefund /> },
          { path: 'order/recharge', element: <RechargeRecord /> },
          { path: 'order/renewal', element: <RenewalRecord /> },
          { path: 'order/withdrawal', element: <WithdrawalRecord /> },
          { path: 'wallet/account', element: <WalletAccount /> },
          { path: 'wallet/detail', element: <WalletDetail /> },
          { path: 'wallet/record', element: <WalletRecord /> },
          { path: 'wallet/subscribe', element: <WalletSubscribe /> },
          { path: 'wallet/topup', element: <WalletTopup /> },
          { path: 'system/email', element: <Email /> },
          { path: 'system/app', element: <AppVersion /> },
          { path: 'system/user', element: <User /> },
          { path: 'system/certificate', element: <Certificate /> },
          { path: 'system/icard', element: <ICard /> },
          { path: 'system/idardlist', element: <IDardList /> },
          { path: 'system/dictionary-data', element: <DictionaryData /> },
          { path: 'system/dictionary-data/:dictType', element: <DictionaryData /> },
          { path: 'authority/role', element: <Role /> },
        { path: 'authority/privacy', element: <PrivacyAgreementInfo /> },
        { path: 'authority/operation', element: <Operation /> },
        { path: 'authority/menu', element: <MenuPage /> },
        { path: 'authority/login', element: <LoginInfo /> },
        { path: 'authority/authorization', element: <Authorization /> },
          { path: 'system/dictionary-data/:codesId/:dictType', element: <DictionaryData /> },
          { path: 'helpcenter/chat', element: <HelpCenterChat /> },
          { path: 'promote/config', element: <PromoteConfig /> },
        ],
      },
    ],
  },
  { path: '*', element: <Navigate to="/" replace /> },
];

export default routes;